import { createContext,useContext,useReducer } from "react";
export const LgContext = createContext();
export const useLgContext = ()=>useContext(LgContext);
const lgState = {username:'',pwd:'',isLogin:false}
const LgReducer =(state,action)=>{
    switch(action.type){
        //登录成功返回值--username
        case 'dlcg':
            return{
                ...state,
                username:action.username,
            }
        default:
            return state;
    }
}
const LgProvider = ({children})=>{
    const [state,dispatch] = useReducer(LgReducer,lgState);
    return (
        <LgContext.Provider
            value={
                {state,dispatch}
            }
        >
            {children}
        </LgContext.Provider>
    )
}
export default LgProvider;